package com.example.myapplication.HomeRecyclerViewAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.HomeRecyclerViewFragment.HomeRecyclerViewBean.XianShiZheKuoBean;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class XianShiZheKouAdapter extends RecyclerView.Adapter<XianShiZheKouAdapter.ViewHolder> {
    List<XianShiZheKuoBean> list=new ArrayList<>();

    public XianShiZheKouAdapter(List<XianShiZheKuoBean> list) {
        this.list = list;
    }
    static class ViewHolder extends RecyclerView.ViewHolder{
        View view;
        ImageView img;
        TextView name;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view=itemView;
            img=view.findViewById(R.id.XuanShiZheKuo_MoKuai_img);
            name=view.findViewById(R.id.XuanShiZheKuo_MoKuai_name);
        }

    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.xianshizhekuo_mokuai,parent,false);
        final ViewHolder viewHolder=new ViewHolder(view);
        viewHolder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int Postition=viewHolder.getAdapterPosition();
                XianShiZheKuoBean xianShiZheKuoBean=list.get(Postition);
                Toast.makeText(view.getContext(), xianShiZheKuoBean.getName(), Toast.LENGTH_SHORT).show();

            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        XianShiZheKuoBean xianShiZheKuoBean=list.get(position);
        holder.img.setImageResource(xianShiZheKuoBean.getImg());
        holder.name.setText(xianShiZheKuoBean.getName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

}
